// pages/classify/classify.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeKey: 0,
    tabIndex: 0,
    page:1,
    cateName:'',
    thumbUrl:getApp().globalData.thumbUrl,
    content:""
  },
  getTab(e) {
    var that=this;
    var id=e.currentTarget.dataset.id;
    var param={pid:id};
    app.wxRequest('POST', "Index/getCateList", param, (res) => {
      var data=res.data;
      that.setData({
        cateName:data.cateName,
        twoLevelList:data.twoLevelList
      })
    }, (err) => {
      console.log(err.errMsg)
    })
    this.setData({
      tabIndex: e.currentTarget.dataset.index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var param={};
    app.wxRequest('POST', "Index/getCateList", param, (res) => {
      var data=res.data;
      that.setData({
        oneLevelList:data.oneLevelList,
        cateName:data.oneLevelList[0].name,
        twoLevelList:data.twoLevelList
      })
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  getContent:function(e){
    var that=this;
    var content=e.detail.value;
    // console.log(e)
    that.setData({
      content:content
    })
  },
  inputConfirm:function(){
    var that=this;
    var content=that.data.content;
    if(content){
        wx.navigateTo({
          url: '../searchRes/searchRes?content='+content,
        })
    }else{
      wx.showToast({
        title: '请输入商品名称',
        icon:"none",
        duration:1500
      })
    }
  },

  // /**
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage: function () {

  // },
  toDetail(e){
    var id=e.currentTarget.dataset.id;
    var name=e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/pages/classifyDetail/classifyDetail?id='+id+"&name="+name,
    })
  }
})